import { methods, request } from '@/utils/request'; //设置自己的request路径

const actions = {
  getusrBaseInfo: {
    //获取用户基本信息
    name: 'getusrBaseInfo',
    url: '/api/stuinfo/getbase',
  },
  putusrBaseInfo: {
    //设置用户基本信息
    name: 'putusrBaseInfo',
    url: '/api/stuinfo/setbase'
  },
  getusrRepotInfo: {
    //获取用户到站信息
    name: 'getusrRepotInfo',
    url: '/api/stuinfo/getreport'
  },
  putusrRepotInfo: {
    //设置用户到站信息
    name: 'putusrRepotInfo',
    url: '/api/stuinfo/setreport'
  },
  getusrFamilyInfo: {
    //获取用户家庭信息
    name: 'getusrFamilyInfo',
    url: '/api/stuinfo/getfamily'
  },
  putusrFamilyInfo: {
    //设置用户家庭信息
    name: 'putusrFamilyInfo',
    url: '/api/stuinfo/setfamily'
  },
  getusrTuitionInfo: {
    //获取用户学费信息
    name: 'getusrTuitionInfo',
    url: '/api/stuinfo/getpayment'
  },
  putusrTuitionInfo: {
    //设置用户学费信息
    name: 'putusrTuitionInfo',
    url: '/api/stuinfo/setpayment'
  },
};

const customRequest = (action: any, token: any, formdata: any = null) => {
  const options: any = {
    headers : {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: localStorage.getItem("token") ? localStorage.getItem("token"):'',
    }
  };
  let url = action.url;
  switch (action.name) {
    case actions.getusrBaseInfo.name: //获取用户基本信息
      options['method'] = methods.get;
      // url += formdata;
      // console.log(url);
      break;
    case actions.putusrBaseInfo.name: //设置用户信息
      options['method'] = methods.put;
      options['body'] =JSON.stringify(formdata) ;
      // console.log(url);
      break;
    case actions.getusrRepotInfo.name: //获取用户到站信息
      options['method'] = methods.get;
      // console.log(url);
      break;
    case actions.putusrRepotInfo.name: //设置用户到站信息
      options['method'] = methods.put;
      options['body'] =JSON.stringify(formdata) ;
      // console.log(url);
      break;
    case actions.getusrFamilyInfo.name: //获取用户家庭信息
      options['method'] = methods.get;
      // console.log(url);
      break;
    case actions.putusrFamilyInfo.name: //设置用户到站信息
      options['method'] = methods.put;
      options['body'] =JSON.stringify(formdata) ;
      // console.log(url);
      break;
    case actions.getusrTuitionInfo.name: //获取用户学费信息
      options['method'] = methods.get;
      // console.log(url);
      break;
    case actions.putusrTuitionInfo.name: //    //设置用户学费信息
      options['method'] = methods.put;
      options['body'] =JSON.stringify(formdata) ;
      // console.log(url);
      break;
    default:
  }
  return request(url, options);
};

export function getusrBaseInfo(token: any, formdata: any) {//获取用户基本信息
  return customRequest(actions.getusrBaseInfo, token, formdata);
}
export function putusrBaseInfo(token: any, formdata: any) {///设置用户信息
  return customRequest(actions.putusrBaseInfo, token, formdata);
}
export function getusrRepotInfo(token: any, formdata: any) {//获取用户到站信息
  return customRequest(actions.getusrRepotInfo, token, formdata);
}
export function putusrRepotInfo(token: any, formdata: any) {///设置用户到站信息
  return customRequest(actions.putusrRepotInfo, token, formdata);
}
export function getusrFamilyInfo(token: any, formdata: any) {//获取用户家庭信息
  return customRequest(actions.getusrFamilyInfo, token, formdata);
}
export function putusrFamilyInfo(token: any, formdata: any) {///设置用户到站信息
  return customRequest(actions.putusrFamilyInfo, token, formdata);
}
export function getusrTuitionInfo(token: any, formdata: any) {//获取用户家庭信息
  return customRequest(actions.getusrTuitionInfo, token, formdata);
}
export function putusrTuitionInfo(token: any, formdata: any) {    //设置用户学费信息
  return customRequest(actions.putusrTuitionInfo, token, formdata);
}
